package com.xizi.秋招笔试.qixinan;

/**
 * @author xizizzz
 * @description: TODO
 * @date 2021-8-23下午 04:13
 */
public class Test1 {
    public static void main(String[] args) {
        int[] fraction = getFraction(0.1415926535898f);
        System.out.println(8.0 / 57.0);
        System.out.println(16.0 / 113.0);
        System.out.println(fraction[0] + " " + fraction[1]);
    }

    public static int[] getFraction(float a) {
        int[] res = new int[2];
        float min = Float.MAX_VALUE;
        for (int i = 1; i < 200; i++) {
            for (int j = 1; j < 200; j++) {
                float t1 = (float) (i * 1.0);
                float t2 = (float) (j * 1.0);
                float tmp = t1 / t2;
                if (Math.abs(tmp - a) < min) {
                    min = Math.abs(tmp - a);
                    res[0] = i;
                    res[1] = j;
                }
            }
        }
        return res;
    }
}
